<?php
/*
 * author: P.L.A
 * create: 2017-08-23
 * */

namespace app\index\model;
use think\Model;

class User extends Model{
	//设置表名
    protected $table = 'am_user';

    //设置最近登录时间
	protected function setLastLoginTimeAttr(){
		return time();
	}
	
	protected function getLastLoginTimeAttr($time){
		return $time;
	}
	
	//设置最近登录IP
	protected function setLastLoginIpAttr(){
		return $_SERVER['REMOTE_ADDR'];
	}
	
	//设置用户注册时间
	protected function setCreateAtAttr(){
		return time();
	}
	
	//用户登录获取登录次数
	public function getLoginCountAttr($id){
	    $res = query('select login_count from'.$table.' where id = '.$id);
		return $res;
	}
	
	
	//设置用户每次登录 loginCount+1
    public function setLoginCountAttr(){
		$count = getLoginCountAttr() + 1;
		return $count;
	}
	
	
	
    // status属性读取器
    /*protected function getStatusAttr($value)
    {
        $status = [-1 => '删除', 0 => '禁用', 1 => '正常', 2 => '待审核'];
        return $status[$value];
    }*/


    //protected $createTime = 'create_time';
    //protected $updateTime = 'update_time';
}

?>